package com.calligraphy.order.handler;

import com.alibaba.fastjson.JSONObject;
import com.calligraphy.bases.utils.SetMsg;
import com.calligraphy.order.exception.OrderException;
import com.calligraphy.order.exception.ResponseBankException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 统一异常处理
 * @Author hy
 * @Date 2019/1/28 11:20
 **/
@ControllerAdvice
public class OrderExceptionHandler {

    @ExceptionHandler(value = OrderException.class)
    @ResponseBody
    public JSONObject handlerSellerException(OrderException e){
        JSONObject json = new JSONObject();
        SetMsg.setMessage(json,e.getCode(), e.getMessage());
        return json;
    }

    @ExceptionHandler(value = ResponseBankException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public void handleResponseBankException(){

    }
}
